/**
 * 数据字典
 * 作者：夏冬琦 2021-08
 */


import { reactive } from 'vue'
import {get} from '@/common'



const ddo = {

	refresh: true,//是否刷新

	text(mark, code) {
		const option = this[mark].find(item => item.value === code);
		return option ? option.label : '';
	},

	windowInnerHeight: document.body.clientHeight,

	homeElCardBodyHeight:document.body.clientHeight-50-30-10-2-51-10,
	// windowInnerHeight（含滚动条）-50(header)-30(footer)-10(main的padding)-卡片边框高度：2 - 卡片头的高度:51 - 卡片体的上下填充：10
	// document.body.clientHeight（不含滚动条）-50(header)-30(footer)-10(main的padding)-卡片边框高度：2 - 卡片头的高度:51 - 卡片体的上下填充：10
	

	//数据状态
	dataStatus: [
		{ value: '00', label: '未确定' },
		{ value: '22', label: '已确定' },
		{ value: '55', label: '已启用' },
		{ value: '77', label: '已禁用' },
		{ value: '99', label: '逻辑删除' }
	],

	dataStatusColorMap: {
		"00": "#303133",
		"22": "#409EFF",
		"55": "#67C23A",
		"77": "#909399",
		"99": "#C0C4CC"
	},

	//产品类型
	prodTypes:[
		{ value: 1, label: '白布' },
		{ value: 2, label: '色布' },
		{ value: 3, label: '无底花布' },
		{ value: 4, label: '有底花布' }		
	],

	//质量等级
	prodLevels:[
		{ value: '01', label: '一等品' },
		{ value: '02', label: '二等品' },
		{ value: '03', label: '三等品' },
		{ value: '04', label: '等外品' }	
	],

	//流程定义信息（状态信息）
	processDefList:[],

	//生产加工状态（组状态）
	groupStatus:[],

	//成品状态
	productStatus:[],

	//包装状态
	storeStatus:[],

	//性别
	sex: [{
		value: 1,
		label: '男'
	}, {
		value: 2,
		label: '女'
	}],

	//学生类型
	studentType: [{
		value: 1,
		label: "专科在读"
	}, {
		value: 2,
		label: "本科在读"
	}, {
		value: 3,
		label: "硕士在读"
	}, {
		value: 4,
		label: "博士在读"
	}, {
		value: 5,
		label: '博士后在读'
	}],

	//爱好
	hobby: [
		{ value: 1, label: '篮球' },
		{ value: 2, label: '小说' },
		{ value: 3, label: '游泳' },
		{ value: 4, label: '小提琴' },
		{ value: 5, label: '画画' },
		{ value: 6, label: '旅游' }
	],

	getHobbyString(hobbyCodeString, delimiter) {
		if (hobbyCodeString && (hobbyCodeString instanceof String || typeof hobbyCodeString === 'string')) {
			const arr = hobbyCodeString.split(delimiter || ',');
			return this.hobby.filter(item => arr.some(code => Number(code) == item.value)).map(item => item.label).join(delimiter || ',');
		}
		return '';
	},

	getTitleString(codeString, delimiter) {
		if (codeString && (codeString instanceof String || typeof codeString === 'string')) {
			const arr = codeString.split(delimiter || ',');
			return this.title.filter(item => arr.some(code => Number(code) == item.value)).map(item => item.label).join(delimiter || ',');
		}
		return '';
	},

	edu: [
		{ value: 1, label: '高中/中专' },
		{ value: 2, label: '专科' },
		{ value: 3, label: '本科' },
		{ value: 4, label: '硕士' },
		{ value: 5, label: '博士' }
	],

	//初始化字典数据，forced表示是否强制从服务器获取最新数据
	init(forced) {
		
		if (this.refresh || forced) {

			

			//在这里可以加入初始化逻辑

			get("/public/base/process-def").then((result) => {
				this.processDefList = result.data;
				this.groupStatus = this.processDefList.filter(item=>item.pd_cls == 1).map(item=>({value:item.pd_id,label:item.pd_name}));
				this.productStatus = this.processDefList.filter(item=>item.pd_cls == 2).map(item=>({value:item.pd_id,label:item.pd_name}));
				this.storeStatus = this.processDefList.filter(item=>item.pd_cls == 3).map(item=>({value:item.pd_id,label:item.pd_name}));
			});

			window.addEventListener('resize', () => {
				this.windowInnerHeight = document.body.clientHeight;
				this.homeElCardBodyHeight = document.body.clientHeight-50-30-10-2-51-10;
			});
			this.refresh = false;
		}

	}

};

ddo.init();

export default reactive(ddo);
